<template>
  <div></div>
</template>

<script>

export default{
//  beforeRouteEnter (to, from, next) {
//    next(vm => {
//      vm.redirect = encodeURIComponent(from.fullPath != '/setting'? from.fullPath: '')
//    })
//  },
  data() {
    return {
      redirect: ''
    }
  },
  created() {
    if(this.$store.state.userInfo.uid){
      this.$http.post($config.host + '/api/Userbase/logOutLogin', qs.stringify({
        uid: this.$store.state.userInfo.uid,
        client: $config.client_type,
        device: $config.device_type,
        token: this.$store.state.userInfo.token
      })).then((res) => {
        const {code , msg} = res.data
        if(code == 1) {
          this.$store.commit('setUserInfo', {})
          this.$store.commit('setCityCode', '')
          this.$store.commit('setEndAddress', [{
            firstAddress: '',
            detailsAddress: '',
            phone: '',
            lng: '',
            lat: '',
            province: '',
            city: '',
            area: ''
          }])
          this.$store.commit('setStartAddress', {
            firstAddress: '正在获取当前位置...',
            detailsAddress: '',
            phone: '',
            lng: '',
            lat: '',
            province: '',
            city: '',
            area: ''
          })
          window.localStorage.removeItem('user')
          window.localStorage.removeItem('openid')
          window.localStorage.removeItem('nickname')
          window.localStorage.removeItem('headimgurl')
          window.localStorage.removeItem('union_id')
          //this.$vux.toast.text('您已安全退出', 'middle')
          this.$router.push({path: '/login', query: {redirect: this.redirect}})
        } else {
          this.$vux.toast.text(msg, 'middle')
          this.$router.go(-1)
        }
      }).catch((err) => {
        this.$vux.toast.text($config.errMsg, 'middle')
        this.$router.go(-1)
      })
    } else {
      this.$router.push({path: '/login'})
    }

  }
}
</script>
